"use strict";
/* Controllers */
app.controller("b2cBillDetailListController", ['$scope', '$location', '$rootScope', '$routeParams', 'b2cBillDetailListService', function ($scope, $location, $rootScope, $routeParams, b2cBillDetailListService) {

    var vm = $scope.vm;
    vm.p = {};

    $('.date').datetimepicker({
        locale: 'zh-cn',
        format: 'YYYY-MM-DD HH:mm:00'
    });
    $('.date').on('dp.hide', function (e) {
        let curentInput = $(e.currentTarget).find('input')
        let eName = curentInput.attr('name')
        let p = $scope.vm.p
        p[eName] = curentInput.val()
        $scope.$apply()
    })
    $("#startTime").on("dp.change", function (e) {
        $('#endTime').data("DateTimePicker").minDate(e.date);
    });
    $("#endTime").on("dp.change", function (e) {
        $('#startTime').data("DateTimePicker").maxDate(e.date);
    });

    var errorFn = function (result) {
        alert(result);
    };

    $scope.list = function () {
        var vm = $scope.vm;
        var params = {};
        params = vm.p;
        $('#list_table').bootstrapTable('showLoading');
        $("#refreshTable").addClass('disabled');
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                alert("请求失败：" + response.message)
                return;
            }
            $scope.vm.p.startTime = data.startTime
            $scope.vm.p.endTime = data.endTime
            $('#list_table').bootstrapTable('load', data.dataList);
            $('#list_table').bootstrapTable('hideLoading');
            $("#refreshTable").removeClass('disabled');
        };
        b2cBillDetailListService.list(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 100, 1000], pageSize: 30
        });

        $scope.list();
    };


    $scope.queryList = function () {
        $('#list_table').bootstrapTable('refresh');
        $scope.list()
    };

    $scope.initializeController();

}]);

/* Services */
app.service('b2cBillDetailListService', ['ajaxService', function (ajaxService) {

    this.list = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/detail/listB2cBillDetail.do", successFunction, errorFunction);
    };

}]);